<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div><i class="el-icon-user-solid"/> 用户总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">99</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #F56C6C">
          <div><i class="el-icon-shopping-cart-2"/> 销售总量</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">1000000 台</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A">
          <div><i class="el-icon-money"/> 收益额</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">￥ 300000</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C">
          <div><i class="el-icon-s-shop"/> 门店总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">20</div>
        </el-card>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px;height: 450px;"></div>
      </el-col>
      <el-col :span="12">
        <div id="pie" style="width: 500px;height: 400px"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "Home",
  data() {
    return {}
  },
  mounted() { //页面渲染之后再触发
    //折线图、柱状图
    let chartDom = document.getElementById('main');
    let myChart = echarts.init(chartDom);
    let option = {
      title: {
        text: '各季度会员数量统计',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      xAxis: {
        type: 'category',
        data: ["第一季度", "第二季度", "第三季度", "第四季度",]
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: "折线",
          data: [],
          type: 'line'
        },
        {
          name: "柱状",
          data: [],
          type: 'bar'
        }
      ]
    };
    this.request.get("/echarts/members").then(res => {
      option.series[0].data = res.data
      option.series[1].data = res.data
      myChart.setOption(option);

      option1.series[0].data = [
        {name: "第一季度", value: res.data[0]},
        {name: "第二季度", value: res.data[1]},
        {name: "第三季度", value: res.data[2]},
        {name: "第四季度", value: res.data[3]}
      ]
      myChart1.setOption(option1);
    });


    //饼图
    let chartDom1 = document.getElementById('pie');
    let myChart1 = echarts.init(chartDom1);
    let option1 = {
      title: {
        text: '各季度会员数量统计',
        subtext: '比例图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: '入会人数',
          type: 'pie',
          radius: '50%',
          center: ['50%','40%'],
          data: [],
          label: { //饼图图上的文本标签
            show: true,
            position: 'inner',
            textStyle: {
              fontWeight: 300,
              fontsize: 12,
              color: '#fff'
            },
            formatter: '{d}%'
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };

    myChart1.setOption(option1);
  },
  methods: {}
}
</script>

<style scoped>

</style>